//
//  FooterView.m
//  CZTourism
//
//  Created by LiuYihua on 2016/12/7.
//  Copyright © 2016年 南京斯布乔. All rights reserved.
//

#import "FooterView.h"
#import "UIView+Extension.h"

#define RGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define kScreenWidth [[UIScreen mainScreen] bounds].size.width

CGFloat const  DAILY_REPORT_HEIGHT  = 96;
CGFloat const  DAILY_REPORT_WIGHT  = 96;
CGFloat const  DAILY_REPORT_Y  = 200;
CGFloat const  TODO_LABEL_HEIGHT  = 25;
CGFloat const  TODO_LABEL_WEIGHT  = 150;


@interface FooterView()<UIGestureRecognizerDelegate>

/**无内容图片*/
@property (strong, nonatomic) UIImageView *taskView;
/**无内容*/
@property (strong, nonatomic) UILabel * todotaskLabel;
/**刷新*/
@property (nonatomic, strong) UILabel * refreshLabel;


@end

@implementation FooterView


- (instancetype)initWithFrame:(CGRect)frame
{
    if ((self = [super initWithFrame:frame])) {
        
        self.frame = frame;
        
        self.backgroundColor = [UIColor colorWithRed:(239)/255.0 green:(239)/255.0 blue:(244)/255.0 alpha:1.0];
        
        CGRect rect = [[UIScreen mainScreen] bounds];
        
        //无任务图片
        _taskView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"notWork"]];
        _taskView.frame = CGRectMake(rect.size.width / 2- DAILY_REPORT_WIGHT / 2,DAILY_REPORT_WIGHT* 0.5, DAILY_REPORT_WIGHT, DAILY_REPORT_HEIGHT);
        _taskView.centerY = self.centerY- DAILY_REPORT_WIGHT* 0.5;
        
        _taskView.userInteractionEnabled = YES;
        [self addSubview:_taskView];
        
        //有无任务
        _todotaskLabel = [[UILabel alloc]init];
        _todotaskLabel.frame = CGRectMake(0, _taskView.frame.origin.y + DAILY_REPORT_HEIGHT + 10, kScreenWidth, TODO_LABEL_HEIGHT);
        _todotaskLabel.textColor = [UIColor grayColor];
        _todotaskLabel.font = [UIFont systemFontOfSize:16];
        _todotaskLabel.text = @"网络无法连接";
        _todotaskLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_todotaskLabel];
        
        _refreshLabel = [[UILabel alloc]init];
        _refreshLabel.frame = CGRectMake(0, CGRectGetMaxY(_todotaskLabel.frame) + 10, kScreenWidth, TODO_LABEL_HEIGHT);
        _refreshLabel.textColor = RGBColor(82, 164, 250);
        _refreshLabel.font = [UIFont systemFontOfSize:18];
        _refreshLabel.text = @"刷新";
        _refreshLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_refreshLabel];
        
        
        self.userInteractionEnabled = YES;
        
        //给_iconImageView添加点击事件
        
        UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(footerViewTap:)];
        
        [self addGestureRecognizer:singleTap];
        
        singleTap.delegate = self;
        
        singleTap.cancelsTouchesInView = NO;
        
    }
    return self;
}


-(void)setImageName:(NSString *)imageName{

    _imageName = imageName;

    self.taskView.image = [UIImage imageNamed:imageName];
    
    
}

-(void)setTodoText:(NSString *)todoText{
    _todoText = todoText;
    
    self.todotaskLabel.text = todoText;

}


-(void)setTaskViewCenterY:(CGFloat)taskViewCenterY{

    self.taskView.centerY = taskViewCenterY;
    self.todotaskLabel.frame = CGRectMake(0, _taskView.frame.origin.y + DAILY_REPORT_HEIGHT + 10, kScreenWidth, TODO_LABEL_HEIGHT);
    self.refreshLabel.frame = CGRectMake(0, CGRectGetMaxY(_todotaskLabel.frame) + 10, kScreenWidth, TODO_LABEL_HEIGHT);

}


#pragma mark - 图像点击
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}
//头像点击
-(void)footerViewTap:(UITapGestureRecognizer *)sender{

    
    if (_delegate && [_delegate respondsToSelector:@selector(footerViewClick)]) {
        
        [_delegate footerViewClick];
    }
    
}


@end
